package com.test32_网络编程.echo.server;

import java.io.PrintStream;
import java.net.Socket;
import java.util.Scanner;

public class EchoHandle implements Runnable {
    private Socket client;

    public EchoHandle(Socket client) {
        this.client = client;
    }

    @Override
    public void run() {
        try {
            Scanner scanner = new Scanner(client.getInputStream());         // 客户端输入流
            PrintStream out = new PrintStream(client.getOutputStream());    // 客户端输出流
            boolean flag = true;
            while (flag) {
                if (scanner.hasNext()) {
                    String value = scanner.next().trim();
                    if (value.equalsIgnoreCase("exit")) {   // 结束交互
                        out.println("【EchoServer】信息服务交互完毕，已经断开与服务器的连接");
                        flag = false;   // 停止交互
                        break;
                    }
                    out.println("ECHO:" + value);
                }
            }
        } catch (Exception e) {
        }
    }
}
